package com.packenius.library.xspdf;

/**
 * Size of a PDF page.
 * 
 * @author Christian Packenius, 2013.
 */
public class XSPageSize {
  /**
   * Width of a page in user units (1/72 inch).
   */
  public final double width;

  /**
   * Height of a page in user units (1/72 inch).
   */
  public final double height;

  /**
   * Constructor.
   * 
   * @param width Width of the page in user units (1/72 inch).
   * @param height Height of the page in user units (1/72 inch).
   */
  public XSPageSize(double width, double height) {
    if (width <= 0 || height <= 0) {
      throw new XSPdfException("Illegal page size!");
    }
    this.width = width;
    this.height = height;
  }

  /**
   * Returns a page size with exchanged height and width of this one.
   * 
   * @return Rotated page size object.
   */
  public XSPageSize rotate() {
    return new XSPageSize(height, width);
  }

  /**
   * Returns a page size that has bee build with unit type information.
   * 
   * @param width Width of the page.
   * @param height Height of the page.
   * @param unitType Unit of width and height.
   * @return Page size object.
   */
  public static XSPageSize getPageSizeWithUnitType(double width, double height, XSUnitType unitType) {
    return new XSPageSize(XSStatics.convertToUserUnits(width, unitType), XSStatics.convertToUserUnits(height, unitType));
  }

  /**
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    return "PageSize[" + width + "x" + height + "]";
  }
}
